﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Meeting.Public;

namespace Meeting.Web.Admin.MeetingAfter
{
    /// <summary>
    /// AttendanceStatisticsOperation 的摘要说明
    /// </summary>
    public class AttendanceStatisticsOperation : IHttpHandler
    {

        string methodName = "";
        int nPageIndex = 1;
        int nPageSize = 4;

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json;charset=utf-8";

            nPageIndex = CommonFunction.varToIntDef(context.Request.Params["page"], 1);
            nPageSize = CommonFunction.varToIntDef(context.Request.Params["rows"], 15);
            methodName = context.Request.Params["method"];
            switch (methodName)
            {
                case "GetMeetingAttendance":
                    GetMeetingAttendance(context);
                    break;
                case "GetAttendanceDetail":
                    GetAttendanceDetail(context);
                    break;
            }
        }
        BLL.AttendanceStatistics bll = new BLL.AttendanceStatistics();
        //获取签到信息
        private void GetMeetingAttendance(HttpContext context)
        {
            //throw new NotImplementedException();
            string Name = context.Request.Params["Name"];
            string Host = CommonFunction.VarToStr(context.Request.Params["Host"]);
            string Begin = context.Request.Params["Begin"];
            string End = context.Request.Params["End"];

            string sF = " 1=1 ";
            if (!string.IsNullOrEmpty(Name)) sF += " And  Name Like '%" + Name + "%' ";
            if (!string.IsNullOrEmpty(Host)) sF += " And  HostName Like '%" + Host + "%' ";
            if (!string.IsNullOrEmpty(Begin)) sF += " And StartDate >= '" + Begin + "' ";
            if (!string.IsNullOrEmpty(End)) sF += " And  StartDate <= '" + End + "' ";
           
            context.Response.Write(bll.GetMeetingAttendance(nPageIndex, nPageSize, sF));
        }
        public void GetAttendanceDetail(HttpContext context)
        {
            string meetingId = context.Request["Id"];
            bool flagAbsent = CommonFunction.VarToStr(context.Request["IsAbsent"]).ToLower() == "true";
            context.Response.Write(bll.GetAttendanceDetail(meetingId,flagAbsent));
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}